package com.service.component;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@EnableSwagger2
@SpringBootApplication
@MapperScan("com.service.component.*.mapper")
public class CommonComponentApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext  context = SpringApplication.run(CommonComponentApplication.class, args);
        Environment environment = context.getBean(Environment.class);
        log.info(environment.getProperty("server.servlet.context-path")+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"启动成功!!!!" );
    }

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.service.component"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("common-component公共服务组件RESTful APIs")
                .description("https://gitee.com/calvin_it/common-component?_sasdk=f%3F%3DA%3D%3FC%3E")
                .termsOfServiceUrl("https://blog.csdn.net/qq_37840993?spm=1000.2115.3001.5343")
                .contact("程序员Calvin_it")
                .version("1.0.0")
                .build();
    }

}
